import 'package:flutter/material.dart';

class GridCountDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return _gridBuilExtend();
  }

  /*extend 方式 根据大小自动换行处理*/
  Widget _gridViewExtend() {
    return GridView.extent(
      // crossAxisCount: 4,
      maxCrossAxisExtent: 200,
      children: _bulidGridItem(),
      mainAxisSpacing: 10,
      crossAxisSpacing: 20,
      scrollDirection: Axis.horizontal,
    );
  }

  /*count 方式*/
  Widget _gridViewCount() {
    return GridView.count(
      crossAxisCount: 4,
      children: _bulidGridItem(),
      mainAxisSpacing: 10,
      crossAxisSpacing: 20,
      scrollDirection: Axis.horizontal,
    );
  }

  Widget _gridBuilExtend() {
    return GridView.builder(
      scrollDirection: Axis.horizontal,
      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
        crossAxisSpacing: 10,
        maxCrossAxisExtent: 700,
        mainAxisSpacing: 20
      ),
      itemBuilder: (BuildContext context, int index) {
        return _bulidGridItem1(index);
      },
    );
  }

  List<Widget> _bulidGridItem() {
    return List<Widget>.generate(10, (int index) {
      return Container(color: Colors.grey);
    });
  }

  Widget _bulidGridItem1(int index) {
    return Container(color: Colors.grey);
  }
}
